﻿@model Coticula.Web.Models.Results

@{
    ViewBag.Title = string.Format("Solution {0}", Model.Id);
}

@{
    var pageMenu = new MvcHtmlString[] { Html.ActionLink("Solutions", "Index"), };

    if (Roles.IsUserInRole("Administrator"))
    {
        Array.Resize(ref pageMenu, pageMenu.Length + 2);
        pageMenu[pageMenu.Length - 2] = Html.ActionLink("Edit", "Edit", new { id = Model.Id });
        pageMenu[pageMenu.Length - 1] = Html.ActionLink("Delete", "Delete", new { id = Model.Id });
    }
    ViewBag.PageMenu = pageMenu;
}

<h2>@ViewBag.Title</h2>

<script src="@Url.Content("~/Scripts/SyntaxHighlighter/shCore.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/SyntaxHighlighter/shBrushCpp.js")" type="text/javascript"></script>
<script src="@Url.Content("~/Scripts/SyntaxHighlighter/shBrushDelphi.js")" type="text/javascript"></script>
<link href="@Url.Content("~/Content/SyntaxHighlighter/shCore.css")" rel="stylesheet" type="text/css" />
<link href="@Url.Content("~/Content/SyntaxHighlighter/shThemeDefault.css")" rel="stylesheet" type="text/css" />

<script type="text/javascript">
    SyntaxHighlighter.all()
</script>

<fieldset>
    <legend>Result</legend>

    <div class="display-label">DateTime</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Solution.DateTime)
    </div>

    <div class="display-label">User</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.User.UserName)
    </div>

    <div class="display-label">Language</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Solution.Language.Name)
    </div>
    @{
        string brush = "cpp";
        if (Model.Solution.Language.Name == "Pascal")
        {
            brush = "pascal";
        }
    <div class="display-label">Answer</div>
    <div class="display-field">
        <pre class="brush: @brush">@Model.Solution.Answer</pre>
    </div>
    }

    <div class="display-label">Problem</div>
    <div class="display-field">
        @Html.ActionLink((Model.Solution.Problem.Name), "Details", "Problem", new { id = Model.Solution.ProblemId }, null)
    </div>

    <div class="display-label">Verdict</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Verdict.Name)
    </div>
    
    @if (Model.VerdictId == 3)
    {
    <div class="display-label" id="showCompileResult">Compile result (click to show)</div>
        <div class="display-field" id="compileResult" style="display: none;">
            @if (Model.CompiledDetail != null)
            {
                <pre>@Html.Encode(Model.CompiledDetail.Output)</pre>
            }
            else
            {
                <pre>Empty</pre>
            }
        </div>
    }

    <div class="display-label">Score</div>
    <div class="display-field">
        @Html.DisplayFor(model => model.Score)
    </div>

    <div class="display-label" id="showTestsResult">Verdicts by tests (click to show)</div>
    <div class="display-field" id="testsResult" style="display: none;">
        @if (Model.TestsResults != null && Model.TestsResults.Count > 0)
        {
            foreach (var testResult in Model.TestsResults)
            {
                <div>@testResult.TestId. @testResult.Verdict.Name</div>
            }
        }
        else
        {
            <div>Empty</div>
        }
        (Click here to hide)
    </div>
    <script>
        $('#testsResult').click(function () {
            $('#testsResult').hide('slow');
        });
        $('#showTestsResult').click(function () {
            $('#testsResult').show('slow');
        });

        $('#compileResult').click(function () {
            $('#compileResult').hide('slow');
        });
        $('#showCompileResult').click(function () {
            $('#compileResult').show('slow');
        });
    </script>
</fieldset>

